package com.kasa.zto.common;

import com.kasa.zto.ZTODecoder;
import com.kasa.zto.ZTOEncoder;
import com.kasa.zto.ZTOException;
import com.kasa.zto.ZTOType;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2007</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class CommHead implements ZTOType
{
    private static final long serialVersionUID = 6722952320099086176L;
    
    public int moduleID;//模块ID的定义，目前暂时没用到
    public String moduleName;
    public String userName;
    public String ipAddress;
    public String port;
    public int messageType = CommConstant.MESSAGE_TYPE_SYN;
    public int cmdCode;
    public int errorCode;
    public String errorMessage;

    public CommHead()
    {
    }

    public void encode(ZTOEncoder encoder) throws ZTOException
    {
        encoder.encode_int(moduleID);
        encoder.encodeString(moduleName);
        encoder.encodeString(userName);
        encoder.encodeString(ipAddress);
        encoder.encodeString(port);
        encoder.encode_int(messageType);
        encoder.encode_int(cmdCode);
        encoder.encode_int(errorCode);
        encoder.encodeString(errorMessage);
    }

    public void decode(ZTODecoder decoder) throws ZTOException
    {
        moduleID = decoder.decode_int();
        moduleName = decoder.decodeString();
        userName = decoder.decodeString();
        ipAddress = decoder.decodeString();
        port = decoder.decodeString();
        messageType = decoder.decode_int();
        cmdCode = decoder.decode_int();
        errorCode = decoder.decode_int();
        errorMessage = decoder.decodeString();
    }
}
